#ifndef __DES_CARD__
#define __DES_CARD__
#include <vector>
#include <napi.h>
#include <iostream>
#include <iomanip>
extern "C"
{
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
//#define EncrySector  1
#define OK 1

typedef unsigned char   ElemType;
typedef unsigned char INT8U;

INT8U ByteToBit(ElemType ch,ElemType bit[8]);    //字节转换成二进制
INT8U BitToByte(ElemType bit[8],ElemType *ch);  //二进制转换成字节
INT8U Char8ToBit64(ElemType ch[8],ElemType bit[64]);  //将长度为8的字符串转为二进制位串
INT8U Bit64ToChar8(ElemType bit[64],ElemType ch[8]);  //将二进制位串转为长度为8的字符串
INT8U DES_MakeSubKeys(ElemType key[64],ElemType subKeys[16][48]);  //生成子密钥
INT8U DES_PC1_Transform(ElemType key[64], ElemType tempbts[56]);  //密钥置换1
INT8U DES_ROL(ElemType data[56], INT8U time);  //循环左移
INT8U DES_IP_Transform(ElemType data[64]);  //IP置换
INT8U DES_IP_1_Transform(ElemType data[64]);  //IP逆置换
INT8U DES_E_Transform(ElemType data[48]);  //扩展置换
INT8U DES_P_Transform(ElemType data[32]);  //P置换
INT8U DES_SBOX(ElemType data[48]);  //S盒置换
INT8U DES_XOR(ElemType R[48], ElemType L[48],INT8U count);  //异或
INT8U DES_Swap(ElemType left[32],ElemType right[32]);  //交换
INT8U DES_EncryptBlock(ElemType plainBlock[8], ElemType subKeys[16][48], ElemType cipherBlock[8]);  //加密单个分组
INT8U DES_DecryptBlock(ElemType cipherBlock[8], ElemType subKeys[16][48], ElemType plainBlock[8]);  //解密单个分组
INT8U DES_Encryptcard(ElemType *card, ElemType *keyStr,ElemType *ciphercard);  //加密卡号
INT8U DES_Decryptcard(ElemType *ciphercard, ElemType  *keyStr,ElemType *plaincard); //解密卡号
INT8U adminauther(ElemType *adminKey,ElemType *cipherKey);//授权卡密码验证
INT8U cardSNto8B(ElemType  *cardId, ElemType *cardString);//将卡号的四位转为八位
INT8U writeKeystr(ElemType *cipherKey,ElemType *writekeyStr);//将8字节的密钥转换为16字节的写入密钥
INT8U noEncryauth(ElemType * CardId);//原始密码验证
INT8U readkey(ElemType    adminkey[],ElemType keylen);//读取键值
INT8U soundnum(INT8U num);
}
#endif